//
//  CaptchaViewController.m
//  BaoGongBao
//
//  Created by User on 14/12/3.
//  Copyright (c) 2014年 irule. All rights reserved.
//

#import "CaptchaViewController.h"

@interface CaptchaViewController ()

@end

@implementation CaptchaViewController

- (IBAction)rightBarButtonItemSelector:(id)sender
{
	[self.mTFMobile resignFirstResponder];
	if ([self.mTFMobile.text isEqualToString:@""]) {

		[[iToast makeText:@"请输入验证码"] show];
		return;
	}

	//-->param:{PlatForm=3, mobilenum=15256995851, appid=HMP_001, DeviceName=MI 2S, OSName=android 4.1.1, loginplace=中国,安徽省,合肥市,蜀山区,创业大道,117.201456,31.861073, deviceid=860955020541003}
    if(gloginplace == nil)
    {
        gloginplace = @"";
    }
	NSDictionary *dictionary = @{
								 @"RegistCode"	: self.mTFMobile.text,
								 @"mobilenum"	: self.strMobile,
								 @"PlatForm"	: kSys_PlatForm,
								 @"appid"		: kSys_appid,
								 @"DeviceName"	: [UIDevice currentDevice].model,
								 @"OSName"		: [NSString stringWithFormat:@"%@ %@", [UIDevice currentDevice].systemName, [UIDevice currentDevice].systemVersion],
								 @"Location"	: _myLocations,
								 @"deviceid"	: kSys_deviceid//[OpenUDID value]
								 };
	[[NetWorkRequestApi sharedNetWorkRequestApi] RegisterNext:dictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {

		switch ([[responseObject objectForKey:@"Tag"] integerValue]) {
			case 0:
			{
				[[iToast makeText:[responseObject objectForKey:@"Message"]] show];

				NSDictionary *dictionary = @{@"appid"		: kSys_appid,
											 @"deviceid"	: kSys_deviceid,//[OpenUDID value],
											 @"Location"	: gloginplace,//account,
											 @"OSName"		: [NSString stringWithFormat:@"%@ %@", [UIDevice currentDevice].systemName, [UIDevice currentDevice].systemVersion]
											 };
				[[NetWorkRequestApi sharedNetWorkRequestApi] nrLogin:dictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
					NSLog(@"%@", responseObject);
					switch ([[responseObject objectForKey:@"Tag"] integerValue]) {
						case 1:
						{
							[[iToast makeText:[responseObject objectForKey:@"Message"]] show];
							gUserInfo = responseObject;
							gToken = [responseObject objectForKey:@"Token"];
						}
							break;
						case 2:
						{
							UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:[responseObject objectForKey:@"Message"] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
							alertView.tag = kAlertViewTag_isRegister;
							[alertView show];
						}
							break;
						default:
							break;
					}
				} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
					
					[[iToast makeText:kNRStr_LoadDataFailure] show];
				}];


				[self dismissViewControllerAnimated:YES completion:nil];
			}
				break;
			case 1:
			{
				[self dismissViewControllerAnimated:YES completion:nil];
			}
			default:
				break;
		}
	} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

		[[iToast makeText:kNRStr_LoadDataFailure] show];
	}];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

	UILabel *lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 80)];
	lbTitle.textColor = [UIColor whiteColor];
	lbTitle.textAlignment = NSTextAlignmentCenter;
	lbTitle.text = @"请输入验证码";
	self.navigationItem.titleView = lbTitle;
//	self.title = @"请输入验证码";
	//self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemSelector:)];
	self.view.backgroundColor = [UIColor whiteColor];

//	self.mTFMobile = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, CGRectGetWidth(self.view.frame)-40, 40)];
//	self.mTFMobile.placeholder = @"请输入验证码";
//	self.mTFMobile.keyboardType = UIKeyboardTypePhonePad;
//	self.mTFMobile.layer.cornerRadius = 5;
//	self.mTFMobile.layer.borderWidth = 1;
//	self.mTFMobile.layer.borderColor = [UIColor lightGrayColor].CGColor;
//	[self.view addSubview:self.mTFMobile];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)sendAgain:(id)sender{
    if(gloginplace == nil)
    {
        gloginplace = @"";
    }
    
    NSDictionary *dictionary = @{@"mobilenum"	: self.strMobile,
                                 @"PlatForm"	: kSys_PlatForm,
                                 @"appid"		: kSys_appid,
                                 @"DeviceName"	: [UIDevice currentDevice].model,
                                 @"OSName"		: [NSString stringWithFormat:@"%@ %@", [UIDevice currentDevice].systemName, [UIDevice currentDevice].systemVersion],
                                 @"loginplace"	: gloginplace,
                                 @"deviceid"	: kSys_deviceid//[OpenUDID value]
                                 };
    [[NetWorkRequestApi sharedNetWorkRequestApi] nrRegister:dictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        switch ([[responseObject objectForKey:@"Tag"] integerValue]) {
            case 1:
            {
                [[iToast makeText:[responseObject objectForKey:@"Message"]] show];
            }
                break;
            case 0:
            {
                UIAlertView *alt = [[UIAlertView alloc]initWithTitle:nil message:[responseObject objectForKey:@"Message"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alt show];
            }
            default:
                break;
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [[iToast makeText:kNRStr_LoadDataFailure] show];
    }];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
